import {IGoodsPageRow, IStoreProductRow} from "@/api/modules/pointsMall";
import {request,post} from "@/utils/request";
import ApiResult from "@/api/base/ApiResult";

export interface IDeleteCompositionOptions {
  successCallback: () => void
}

export function useDeleteProduct() {
  const handleProductDelete = async (url: string, rowData: IStoreProductRow, goodsRow: IGoodsPageRow) => {
    const rs: ApiResult<any> = await request(url, {id: rowData.id})

    if (rs.code === 200) {
      const productIndex = goodsRow.products?.findIndex(item => item.id === rowData.id) ?? -1
      if (productIndex > -1) {
        goodsRow.products?.splice(productIndex, 1)
        ElMessage.success('删除成功')
      }
    }
  }

  return {
    handleProductDelete
  }
}
